# import time
# import random
# import queue
# from threading import Thread
#
# def func(q,i):
#     print('start',i)
#     time.sleep(random.randint(1,5))
#     print('end',i)
#     q.put(i*(i+1))
#
# def print_func(q):
#     print(q.get())
#
# q=queue.Queue()
# for i in range(20):
#     Thread(target=func,args=(q,i)).start()
# for i in range(20):
#     Thread(target=print_func,args=(q,)).start()

import time,random
from threading import current_thread
from concurrent.futures import ThreadPoolExecutor

def func(a,b):
    print(current_thread().ident,'start',a,b)
    time.sleep(random.randint(1,4))
    print(current_thread().ident, 'end', a, b)
    return a*b

def print_func(ret):
    print(ret.result())

if __name__ == '__main__':
    tp=ThreadPoolExecutor(4)
    for i in range(20):
        ret=tp.submit(func,i,i+1)
        ret.add_done_callback(print_func)





